#!/bin/bash
#
# Test the Nginx image in OpenShift.
#
# IMAGE_NAME specifies a name of the candidate image used for testing.
# The image has to be available before this script is executed.
#

THISDIR=$(dirname ${BASH_SOURCE[0]})

source ${THISDIR}/test-lib.sh
source ${THISDIR}/test-lib-openshift.sh
source ${THISDIR}/test-lib-nginx.sh

# TODO: branch should be changed to master, once code in example app
# stabilizes on with referencing latest version
BRANCH_TO_TEST=master

set -eo nounset

trap ct_os_cleanup EXIT SIGINT

ct_os_check_compulsory_vars

ct_os_enable_print_logs

ct_os_cluster_up

# test local app
ct_os_test_s2i_app ${IMAGE_NAME} "${THISDIR}/test-app" . 'Test NGINX passed'

# test remote example app
ct_os_test_s2i_app ${IMAGE_NAME} "https://github.com/sclorg/nginx-ex.git#${BRANCH_TO_TEST}" . 'Welcome to your static nginx application on OpenShift'

# test template from the example app
ct_os_test_template_app ${IMAGE_NAME} \
                        https://raw.githubusercontent.com/sclorg/nginx-ex/${BRANCH_TO_TEST}/openshift/templates/nginx.json \
                        nginx \
                        'Welcome to your static nginx application on OpenShift' \
                        8080 http 200 "-p SOURCE_REPOSITORY_REF=${BRANCH_TO_TEST} -p NGINX_VERSION=${VERSION} -p NAME=nginx-testing"

# Check the imagestream
test_nginx_imagestream

OS_TESTSUITE_RESULT=0

ct_os_cluster_down

# vim: set tabstop=2:shiftwidth=2:expandtab:

